<?php
class Invoice extends InvoicePeer
{
	function Invoice()
	{
		parent::InvoicePeer();
	}
	
	
	public static function getAllInvoices()
	{
		$database = new Database();
		$query = "SELECT id FROM invoice";
		$result = $database->query($query);
		$ids = $database->fetch_array($result);
		$invoices = array();
		foreach ($ids as $id) {
			$invoice = new Invoice();
			$invoice->select($id['id']);
			$invoices[] = $invoice;
		}
		return $invoices;
	}
	
	function getAmount()
	{
		$amount = 0;
		$orders = ClientOrder::getAllOrders($this->getid());
		foreach ($orders as $order) {
			if ($order->gettour_id()) { // it's an order for tour
				$tour = new Tour();
				$tour->select($order->gettour_id());
				$customers = Customer::getAllCustomers($order->getid());
				$amount += $tour->getRealPrice()*count($customers);
			} elseif ($order->gethotel_id()) { // it's an order for hotel
				$days_number = $order->count_day();
				$rooms = OrderRoom::getAllRoomsByOrder($order->getid());
				foreach ($rooms as $room) {
					$amount += $room->getRealPrice() * $days_number;
				}
			} elseif ($order->gettransfer_id()) { // it's an order for transfer
				
			}
		}
		return $amount;
	}
}
?>